import Vue from 'vue'
import { getScore } from '@/http/api.js'
Vue.mixin({
	data () {
	    return {
			userScore: ''
	    }
	},
	methods: {
		goPage(url, params) {
			const authStatus = this.$store.state.authStatus
			if(!authStatus){
				uni.navigateTo({
					url: '/pages/login/index/index'
				})
				return
			}
			switch(authStatus){
				case 'UNREGISTERED':
				// 未注册
					uni.navigateTo({
						url: '/pages/login/index/index'
					})
				break;
				case 'AUTHENTICATING':
				// 认证中 ->审核中页面
					uni.reLaunch({
						url: '/pages/community/approving/approving'
					})
				break;
				// break;
				case 'AUTHENTICATION_FAILED':
				// 认证失败 ->社区认证
					uni.navigateTo({
						url: `/pages/community/index/index?isFailed=true`
					})
				break;
				default:
					if(!url){
						uni.showToast({
							title: "功能正在开发中",
							duration: 3000,
							icon: "none"
						});
						return;
					}
					console.log(url);
					if(params){
						uni.navigateTo({
							url: url+'?content='+encodeURIComponent(JSON.stringify(params))
						});
					}else{
						console.log(url)
						uni.navigateTo({
							url: url
						});
					}
				break;
			}
		},
		// 获取个人积分
		getScore() {
			this.$request({
				url: getScore
			}).then((res) => {
				this.userScore = res // 我的积分
			})
		},
		toAutorize(){
			const authStatus = this.$store.state.authStatus
			// authStatus === 'REGISTERED' ||
			if(authStatus === 'UNAUTHORIZED'){
				uni.navigateTo({
					url: '/pages/community/index/index'
				})
			}
		}
	}
})